from django.shortcuts import render

# Create your views here.


# Create your views her.
def login(request):
    def errorHandler(error):
    return render_to_response('login.html', {'error' : error})
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(username = username, password = password)
        if user is not None:
            if user.is_active:
                authLogin(request, user)
                fullName = user.get_full_name
                return render_to_response('logged_in.html', {'full_name': fullName})
            else:
                error = 'Account disabled.'
        return errorHandler(error)
        else:
            error = 'Invalid details entered.'
        return errorHandler(error)

    return render_to_response('login.html')

@login_required
def logout(request):
    authLogout(request)
    return render_to_response('logged_in.html')
